Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
"Cannot read property of undefined."

I have some simple code that I've written in Python. It's working. Now I'm trying to port it to JavaScript. The code is here. I'm getting this error:

sketch.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'compression_ratio')
    at w (sketch.js:7:39)
    at ifsp (sketch.js:37:13)
    at draw (sketch.js:54:14)
    at p5._main.default.redraw (p5.js:71990:27)
    at _draw (p5.js:64140:25)

What's going wrong here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error is here (Starting line 28).

if (prob_sum > r) {
  attractor_index = j - 1;
} else {
  attractor_index = j;
}

If r is smaller than 1/3 (probability value that you have defined in line 51) you will decrement attractors_index using j - 1 and if that happens in the first iteration attractors_index will be -1 as j = 0. In that case attractors[attractors_index] will return undefined and you call w() with undefined instead of the object you expect, hence attractors.compression_ratio will not have a property compression_ratio and the error is thrown.

You can check/ reproduce that easily by manually setting r to > or < 1/3.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda